import * as Mixly from 'mixly';

export const actuator_Buzzer_PWMinit = function (_, generator) {
    generator.definitions_['import board'] = 'import board';
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    var code = 'buzzer=PWM(Timer(Timer.TIMER0, Timer.CHANNEL1, mode=Timer.MODE_PWM), freq=1000, duty=50, pin=board.pin_D[21])\n';
    return code;
}

export const actuator_Buzzer_PWM = function (_, generator) {
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    var bright = generator.valueToCode(this, 'bright', generator.ORDER_ATOMIC);
    var code = "buzzer.freq(" + bright + ")\n";
    return code;
}

export const actuator_led_PWMinit = function (_, generator) {
    generator.definitions_['import board'] = 'import board';
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    var code = 'tim_Bled = Timer(Timer.TIMER1, Timer.CHANNEL3, mode=Timer.MODE_PWM)\nBled=PWM(tim_Bled, freq=1000, duty=100, pin=board.pin_D[22])\n';
    return code;
}

export const actuator_led_PWM = function (_, generator) {
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    var bright = generator.valueToCode(this, 'bright', generator.ORDER_ATOMIC);
    var code = "Bled.duty(" + bright + ")\n";
    return code;
}

export const actuator_Servo_init = function (_, generator) {
    generator.definitions_['import board'] = 'import board';
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    var key = generator.valueToCode(this, 'PIN', generator.ORDER_ATOMIC);
    var time = generator.valueToCode(this, 'time', generator.ORDER_ATOMIC);
    var Timer = time % 3
    var CHANNEL = parseInt(time / 3)
    var code1 = 'tim' + time + ' = Timer(Timer.TIMER' + Timer + ',Timer.CHANNEL' + CHANNEL + ', mode=Timer.MODE_PWM)\n';
    var code2 = 'pse' + key + '=PWM(tim' + time + ', freq=50, duty=2.5, pin=board.pin_D[' + key + '])\n';
    return code1 + code2;
}

export const actuator_Servo_init_new = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    var key = generator.valueToCode(this, 'PIN', generator.ORDER_ATOMIC);
    var time = generator.valueToCode(this, 'time', generator.ORDER_ATOMIC);
    var Timer = time % 3
    var CHANNEL = parseInt(time / 3)
    var code = 'pse' + key + '=servoer.Servo(Timer(Timer.TIMER' + Timer + ',Timer.CHANNEL' + CHANNEL + ', mode=Timer.MODE_PWM),' + key + ')\n';
    return code;
}

export const actuator_Servo = function (_, generator) {
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    var key = generator.valueToCode(this, 'PIN', generator.ORDER_ATOMIC);
    var range = generator.valueToCode(this, 'range', generator.ORDER_ATOMIC);
    var code = "pse" + key + ".duty(" + range + "/18.0+2.5)\n";
    return code;
}

export const actuator_Servo_new = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    var key = generator.valueToCode(this, 'PIN', generator.ORDER_ATOMIC);
    var range = generator.valueToCode(this, 'range', generator.ORDER_ATOMIC);
    var code = "pse" + key + ".set_angle(" + range + ")\n";
    return code;
}

export const actuator_Servo_read_new = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    var key = generator.valueToCode(this, 'PIN', generator.ORDER_ATOMIC);
    var code = "pse" + key + ".read_angle()";
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_syn8266 = function (_, generator) {
    generator.definitions_['import syn6288'] = 'import syn6288';
    var dropdown_uart = this.getFieldValue('mode');
    var data = generator.valueToCode(this, 'data', generator.ORDER_ATOMIC);
    var code = 'syn6288.sendspeak(uart' + dropdown_uart + ',' + data + ')\n';
    return code;
}

export const actuator_PAC9685_init = function (_, generator) {
    generator.definitions_['from servo import Servos'] = 'from servo import Servos';
    var address = generator.valueToCode(this, 'address', generator.ORDER_ATOMIC);
    var sub = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
    var code = 'servos=Servos(' + sub + ',address=' + address + ')\n';
    return code;
}

export const actuator_PAC9685_Servo = function (_, generator) {
    generator.definitions_['from servo import Servos'] = 'from servo import Servos';
    var index = generator.valueToCode(this, 'index', generator.ORDER_ATOMIC);
    var range = generator.valueToCode(this, 'range', generator.ORDER_ATOMIC);
    // var index=index-1;
    var code = "servos.position((" + index + "-1)," + range + ")\n";
    return code;
}

//---------------------------------MIXNO没有的---------------------

export const actuator_rgb_init = function (_, generator) {
    generator.definitions_['import board'] = 'import board';
    generator.definitions_['from modules import ws2812'] = 'from modules import ws2812';
    var SUB = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
    var key = generator.valueToCode(this, 'PIN', generator.ORDER_ATOMIC);
    var num = generator.valueToCode(this, 'num', generator.ORDER_ATOMIC);
    var code = '' + SUB + '=ws2812(board.pin_D[' + key + '],' + num + ')\n';
    return code;
}

export const actuator_rgb_set = function (_, generator) {
    var SUB = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
    var R = generator.valueToCode(this, 'R', generator.ORDER_ATOMIC);
    var G = generator.valueToCode(this, 'G', generator.ORDER_ATOMIC);
    var B = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC);
    var num = generator.valueToCode(this, 'num', generator.ORDER_ATOMIC);
    var code = '' + SUB + '.set_led(' + num + ',(' + G + ',' + R + ',' + B + '))\n';
    return code;
}

export const actuator_rgb_set_new = function (_, generator) {
    var SUB = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
    var R = generator.valueToCode(this, 'R', generator.ORDER_ATOMIC);
    var G = generator.valueToCode(this, 'G', generator.ORDER_ATOMIC);
    var B = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC);
    var num = generator.valueToCode(this, 'num', generator.ORDER_ATOMIC);
    var key = this.getFieldValue('KEY');
    var code;
    if (key == "RGB")
        code = '' + SUB + '.set_led(' + num + ',(' + R + ',' + G + ',' + B + '))\n';
    else
        code = '' + SUB + '.set_led(' + num + ',(' + G + ',' + R + ',' + B + '))\n';
    return code;
}

export const actuator_rgb_display = function (_, generator) {
    var SUB = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
    var code = '' + SUB + '.display()\n';
    return code;
}

export const actuator_moto_init = function (_, generator) {
    generator.definitions_['import moto'] = 'import moto';
    var mode = this.getFieldValue('mode');
    var code = 'moto.moto' + mode + '_init()\n';
    return code;
}

export const actuator_moto_run = function (_, generator) {
    generator.definitions_['import moto'] = 'import moto';
    var mode = this.getFieldValue('mode');
    var speed = generator.valueToCode(this, 'speed', generator.ORDER_ATOMIC);
    var code = 'moto.moto' + mode + '_run(' + speed + ')\n';
    return code;
}

//--开始--------------------------Amigo硬件 -20210920-------------------------------------------------

export const actuator_Amigo_led_PWMinit = function (_, generator) {
    generator.definitions_['import board'] = 'import board';
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    var code = 'tim_Bled = Timer(Timer.TIMER1, Timer.CHANNEL3, mode=Timer.MODE_PWM)\nBinkled=PWM(tim_Bled, freq=1000, duty=100, pin=32)\n';
    return code;
}

export const actuator_Amigo_led_PWM = function (_, generator) {
    generator.definitions_['from machine import Timer'] = 'from machine import Timer';
    generator.definitions_['from machine import PWM'] = 'from machine import PWM';
    var bright = generator.valueToCode(this, 'bright', generator.ORDER_ATOMIC);
    var code = "Binkled.duty(100-" + bright + ")\n";
    return code;
}

//---------20220312----机器狗-------------------------
export const actuator_Dog_servo_config = function (_, generator) {
    generator.definitions_['import config'] = 'import config';
    var code1 = '#只需单独执行此条来校准舵机\n';
    var code2 = 'config.servo_config()\n';
    return code1 + code2;
}

export const actuator_Dog_height = function (_, generator) {
    generator.definitions_['import padog'] = 'import padog';
    var height = generator.valueToCode(this, 'height', generator.ORDER_ATOMIC);
    var code = "padog.height(" + height + ")\n";
    return code;
}

export const actuator_Dog_stable = function (_, generator) {
    generator.definitions_['import padog'] = 'import padog';
    var key = generator.valueToCode(this, 'key', generator.ORDER_ATOMIC);
    var code = "padog.stable(" + key + ")\n";
    return code;
}

export const actuator_Dog_gait = function (_, generator) {
    generator.definitions_['import padog'] = 'import padog';
    var mode = this.getFieldValue('mode');
    var code = 'padog.gait(' + mode + ')\n';
    return code;
}

export const actuator_Dog_gesture = function (_, generator) {
    generator.definitions_['import padog'] = 'import padog';
    var PIT = generator.valueToCode(this, 'PIT', generator.ORDER_ATOMIC);
    var ROL = generator.valueToCode(this, 'ROL', generator.ORDER_ATOMIC);
    var X_goal = generator.valueToCode(this, 'X_goal', generator.ORDER_ATOMIC);
    var code = "padog.gesture(" + PIT + "," + ROL + "," + X_goal + ")\n";
    return code;
}

export const actuator_Dog_init_gesture = function (_, generator) {
    generator.definitions_['import padog'] = 'import padog';
    var code = "padog.gesture(0,0,padog.in_y)\n";
    return code;
}

export const run_state = function (_, generator) {
    var code = this.getFieldValue('flag');
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_Dog_move = function (_, generator) {
    generator.definitions_['import padog'] = 'import padog';
    var speed = generator.valueToCode(this, 'speed', generator.ORDER_ATOMIC);
    var key_l = generator.valueToCode(this, 'key_l', generator.ORDER_ATOMIC);
    var key_r = generator.valueToCode(this, 'key_r', generator.ORDER_ATOMIC);
    var code = "padog.move(" + speed + "," + key_l + "," + key_r + ")\n";
    return code;
}

export const actuator_Dog_stop = function (_, generator) {
    generator.definitions_['import padog'] = 'import padog';
    var code = "padog.state(1)\n";
    return code;
}

// AIBIT-4WD-拓展----------------
export const actuator_4WD_Servo = function (_, generator) {
    generator.definitions_['from motors_4wd import motors'] = 'from motors_4wd import motors';
    var mode = this.getFieldValue('mode');
    var range = generator.valueToCode(this, 'range', generator.ORDER_ATOMIC);
    var code = 'motors.servo(' + mode + ',' + range + ')\n';
    return code;
}

export const actuator_4WD_Motor = function (_, generator) {
    generator.definitions_['from motors_4wd import motors'] = 'from motors_4wd import motors';
    var mode = this.getFieldValue('mode');
    var speed = generator.valueToCode(this, 'speed', generator.ORDER_ATOMIC);
    var code = 'motors.motor(' + mode + ',' + speed + ')\n';
    return code;
}

// ---------无人机拓展----------------
export const actuator_fly_init = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var key = generator.valueToCode(this, 'key', generator.ORDER_ATOMIC);
    var code = 'fly_uav=fly(' + key + ')\n';
    return code;
}

export const actuator_fly_takeOff = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var high = generator.valueToCode(this, 'high', generator.ORDER_ATOMIC);
    var code = 'fly_uav.takeOff(' + id + ',' + high + ')\n';
    return code;
}

export const actuator_fly_flyMode = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.flyMode(' + id + ',' + mode + ')\n';
    return code;
}

export const actuator_fly_xySpeed = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var speed = generator.valueToCode(this, 'speed', generator.ORDER_ATOMIC);
    var code = 'fly_uav.xySpeed(' + id + ',' + speed + ')\n';
    return code;
}

export const actuator_fly_zSpeed = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var speed = generator.valueToCode(this, 'speed', generator.ORDER_ATOMIC);
    var code = 'fly_uav.zSpeed(' + id + ',' + speed + ')\n';
    return code;
}

export const actuator_fly_moveCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var distance = generator.valueToCode(this, 'distance', generator.ORDER_ATOMIC);
    var code = 'fly_uav.moveCtrl(' + id + ',' + mode + ',' + distance + ')\n';
    return code;
}

export const actuator_fly_moveSearchDot = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var distance = generator.valueToCode(this, 'distance', generator.ORDER_ATOMIC);
    var code = 'fly_uav.moveSearchDot(' + id + ',' + mode + ',' + distance + ')\n';
    return code;
}

export const actuator_fly_moveSearchBlob = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var distance = generator.valueToCode(this, 'distance', generator.ORDER_ATOMIC);
    var LIST = generator.valueToCode(this, 'LIST', generator.ORDER_ATOMIC);
    var code = 'fly_uav.moveSearchBlob(' + id + ',' + mode + ',' + distance + ',' + LIST + ')\n';
    return code;
}

export const actuator_fly_moveSearchTag = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var distance = generator.valueToCode(this, 'distance', generator.ORDER_ATOMIC);
    var tagID = generator.valueToCode(this, 'tagID', generator.ORDER_ATOMIC);
    var code = 'fly_uav.moveSearchTag(' + id + ',' + mode + ',' + distance + ',' + tagID + ')\n';
    return code;
}

export const actuator_fly_moveFollowTag = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var distance = generator.valueToCode(this, 'distance', generator.ORDER_ATOMIC);
    var tagID = generator.valueToCode(this, 'tagID', generator.ORDER_ATOMIC);
    var code = 'fly_uav.moveFollowTag(' + id + ',' + mode + ',' + distance + ',' + tagID + ')\n';
    return code;
}

export const actuator_fly_goTo = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var LIST = generator.valueToCode(this, 'LIST', generator.ORDER_ATOMIC);
    var code = 'fly_uav.goTo(' + id + ',' + LIST + ')\n';
    return code;
}

export const actuator_fly_goToTag = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var tagID = generator.valueToCode(this, 'tagID', generator.ORDER_ATOMIC);
    var high = generator.valueToCode(this, 'high', generator.ORDER_ATOMIC);
    var code = 'fly_uav.goToTag(' + id + ',' + tagID + ',' + high + ')\n';
    return code;
}

export const actuator_fly_rotation = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var angle = generator.valueToCode(this, 'angle', generator.ORDER_ATOMIC);
    var code = 'fly_uav.rotation(' + id + ',' + angle + ')\n';
    return code;
}

export const actuator_fly_flyHigh = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var high = generator.valueToCode(this, 'high', generator.ORDER_ATOMIC);
    var code = 'fly_uav.flyHigh(' + id + ',' + high + ')\n';
    return code;
}

export const actuator_fly_flipCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var cir = generator.valueToCode(this, 'cir', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.flipCtrl(' + id + ',' + mode + ',' + cir + ')\n';
    return code;
}

export const actuator_fly_ledCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var LIST = generator.valueToCode(this, 'LIST', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.ledCtrl(' + id + ',' + mode + ',' + LIST + ')\n';
    return code;
}

export const actuator_fly_closeLed = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var code = 'fly_uav.closeLed(' + id + ')\n';
    return code;
}

export const actuator_fly_shootCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.shootCtrl(' + id + ',' + mode + ')\n';
    return code;
}

export const actuator_fly_magnetCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.magnetCtrl(' + id + ',' + mode + ')\n';
    return code;
}

export const actuator_fly_servoCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var angle = generator.valueToCode(this, 'angle', generator.ORDER_ATOMIC);
    var code = 'fly_uav.servoCtrl(' + id + ',' + angle + ')\n';
    return code;
}

//---------Ctrl--------

export const actuator_fly_mvCheckMode = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.mvCheckMode(' + id + ',' + mode + ')\n';
    return code;
}

export const actuator_fly_mvCheckAprilTag = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var tagID = generator.valueToCode(this, 'tagID', generator.ORDER_ATOMIC);
    var code = 'fly_uav.mvCheckAprilTag(' + id + ',' + tagID + ')\n';
    return code;
}

export const actuator_fly_mvCheckBlob = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var LIST = generator.valueToCode(this, 'LIST', generator.ORDER_ATOMIC);
    var code = 'fly_uav.mvCheckBlob(' + id + ',' + LIST + ')\n';
    return code;
}

export const actuator_fly_getMvCheak = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.getMvCheak(' + id + ',' + mode + ')';
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_fly_getMvCheakLine = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.getMvCheakLine(' + id + ',' + mode + ')';
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_fly_getObsDistance = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.getObsDistance(' + id + ',' + mode + ')';
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_fly_getFlySensor = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.getFlySensor(' + id + ',' + mode + ')';
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_fly_lockDir = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.lockDir(' + id + ',' + mode + ')\n';
    return code;
}

export const actuator_fly_flyCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.flyCtrl(' + id + ',' + mode + ')\n';
    return code;
}

export const actuator_fly_photographMode = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.photographMode(' + id + ',' + mode + ')\n';
    return code;
}

export const actuator_fly_roleCtrl = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var data = generator.valueToCode(this, 'data', generator.ORDER_ATOMIC);
    var code = 'fly_uav.roleCtrl(' + id + ',' + data + ')\n';
    return code;
}

export const actuator_fly_getRoleNews = function (_, generator) {
    generator.definitions_['import servoer'] = 'import servoer';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var code = 'fly_uav.getRoleNews(' + id + ',' + mode + ')';
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_fly_clearRoleNews = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var code = 'fly_uav.clearRoleNews(' + id + ')\n';
    return code;
}

export const actuator_fly_move = function (_, generator) {
    generator.definitions_['from flylib import fly'] = 'from flylib import fly';
    var id = generator.valueToCode(this, 'id', generator.ORDER_ATOMIC);
    var mode = this.getFieldValue('mode');
    var LIST = generator.valueToCode(this, 'LIST', generator.ORDER_ATOMIC);
    var code = 'fly_uav.move(' + id + ',' + mode + ',' + LIST + ')\n';
    return code;
}

//-新20211221------PID算法，暂时放此处------------------------------------------//
export const PID_init = function (_, generator) {
    generator.definitions_['import pid'] = 'import pid';
    var sub = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
    var P = generator.valueToCode(this, 'P', generator.ORDER_ATOMIC);
    var I = generator.valueToCode(this, 'I', generator.ORDER_ATOMIC);
    var D = generator.valueToCode(this, 'D', generator.ORDER_ATOMIC);
    var code = "" + sub + "=pid.PID(" + P + "," + I + "," + D + ")\n";
    return code;
}

//-新20211221------PID算法，暂时放此处------------------------------------------//
export const PID_get_pid = function (_, generator) {
    generator.definitions_['import pid'] = 'import pid';
    var sub = generator.valueToCode(this, 'SUB', generator.ORDER_ATOMIC);
    var error = generator.valueToCode(this, 'error', generator.ORDER_ATOMIC);
    var scaler = generator.valueToCode(this, 'scaler', generator.ORDER_ATOMIC);
    var code = "" + sub + ".get_pid(" + error + "," + scaler + ")";
    return [code, generator.ORDER_ATOMIC];
}

//---------------TABIT板载执行器资源---20230520--------------------
export const actuator_tabit_rgb_set = function (_, generator) {
    generator.definitions_['from tabit import *'] = 'from tabit import *';
    var R = generator.valueToCode(this, 'R', generator.ORDER_ATOMIC);
    var G = generator.valueToCode(this, 'G', generator.ORDER_ATOMIC);
    var B = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC);
    var num = generator.valueToCode(this, 'num', generator.ORDER_ATOMIC);
    var code = 'ob_rgb.set_led(' + num + ',(' + R + ',' + G + ',' + B + '))\n';
    return code;
}

export const actuator_tabit_rgb_display = function (_, generator) {
    generator.definitions_['from tabit import *'] = 'from tabit import *';
    var code = 'ob_rgb.display()\n';
    return code;
}

//---------------ASBIT板载执行器 &RGB共用资源---20230720--------------------
export const actuator_xxbit_rgb_set = function (_, generator) {
    var version = Mixly.Boards.getSelectedBoardKey().split(':')[0]
    generator.definitions_['from ' + version + ' import *'] = 'from ' + version + ' import *';
    var R = generator.valueToCode(this, 'R', generator.ORDER_ATOMIC);
    var G = generator.valueToCode(this, 'G', generator.ORDER_ATOMIC);
    var B = generator.valueToCode(this, 'B', generator.ORDER_ATOMIC);
    var num = generator.valueToCode(this, 'num', generator.ORDER_ATOMIC);
    var code = 'ob_rgb.set_led(' + num + ',(' + R + ',' + G + ',' + B + '))\n';
    return code;
}

export const actuator_xxbit_rgb_display = function (_, generator) {
    var version = Mixly.Boards.getSelectedBoardKey().split(':')[0]
    generator.definitions_['from ' + version + ' import *'] = 'from ' + version + ' import *';
    var code = 'ob_rgb.display()\n';
    return code;
}

export const actuator_asbit_esp_reset = function (_, generator) {
    generator.definitions_['from asbit import *'] = 'from asbit import *';
    var code = 'esp32_reset()\n';
    return code;
}

//-----------------LTBIT-板载库----------------
export const actuator_ltbit_Servo = function (_, generator) {
    generator.definitions_['from ltbit import *'] = 'from ltbit import *';
    var mode = this.getFieldValue('mode');
    var range = generator.valueToCode(this, 'range', generator.ORDER_ATOMIC);
    var code = 'on_motor.servo180(' + mode + ',' + range + ')\n';
    return code;
}

export const actuator_ltbit_Motor = function (_, generator) {
    generator.definitions_['from ltbit import *'] = 'from ltbit import *';
    var mode = this.getFieldValue('mode');
    var speed = generator.valueToCode(this, 'speed', generator.ORDER_ATOMIC);
    var code = 'on_motor.motor(' + mode + ',' + speed + ')\n';
    return code;
}

export const actuator_ltbit_get_Servo = function (_, generator) {
    generator.definitions_['from ltbit import *'] = 'from ltbit import *';
    var mode = this.getFieldValue('mode');
    var code = 'on_motor.servo180(' + mode + ')';
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_ltbit_get_Motor = function (_, generator) {
    generator.definitions_['from ltbit import *'] = 'from ltbit import *';
    var mode = this.getFieldValue('mode');
    var code = 'on_motor.motor(' + mode + ')';
    return [code, generator.ORDER_ATOMIC];
}

//---------------AIBIT板载传感器资源---20240122-------------------
export const actuator_aibit_setled = function (_, generator) {
    generator.definitions_['from aibit import *'] = 'from aibit import *';
    var bright = generator.valueToCode(this, 'bright', generator.ORDER_ATOMIC);
    var code = 'ob_led.duty(' + bright + ')\n';
    return code;
}

export const actuator_aibit_getled = function (_, generator) {
    generator.definitions_['from aibit import *'] = 'from aibit import *';
    var code = 'ob_led.duty()';
    return [code, generator.ORDER_ATOMIC];
}

export const NOTE_SELET = function (_, generator) {
    var code = this.getFieldValue('NOTE');
    return [code, generator.ORDER_ATOMIC];
}

export const actuator_aibit_buzzerpitch = function (_, generator) {
    generator.definitions_['from aibit import *'] = 'from aibit import *';
    var fre = generator.valueToCode(this, 'fre', generator.ORDER_ATOMIC);
    var vol = generator.valueToCode(this, 'vol', generator.ORDER_ATOMIC);
    var code = 'buzzer_pitch(' + fre + ',' + vol + ')\n';
    return code;
}

export const actuator_aibit_buzzerstop = function (_, generator) {
    generator.definitions_['from aibit import *'] = 'from aibit import *';
    var code = 'buzzer_stop()\n';
    return code;
}